//
//  Routes.swift
//  PerfectTemplate
//
//  Created by 陈志勇 on 2018/11/12.
//

import PerfectLib
import PerfectHTTP
import PerfectMustache

func makeRoutes() -> Routes {
    var routes = Routes()
    //routes.add(method: .get, uri: "/", handler: handler)
    routes.add(method: .get, uri: "/") { (request, response) in
        let webRoot = request.documentRoot
        mustacheRequest(request: request, response: response, handler: TestHandler(), templatePath: webRoot + "/index.html")
    }
    
    routes.add(method: .get, uri: "/**",
               handler: StaticFileHandler(documentRoot: "./webroot", allowResponseFilters: true).handleRequest)
    
    routes.add(method: .get, uri: "/login") { (request, response) in
        response.setBody(string: "我是/login路径返回信息")
        response.completed()
    }
    
    routes.add(method: .post, uri: "/login", handler: UserHandler.login)
    routes.add(method: .get, uri: "/create", handler: UserHandler.create)
    return routes
}
